let app = getApp()
import {imageUrl} from "../../utils/imageutil"
Page({

  data: {
    imageUrl,
    order_id:'',
    flag:true,
    page:1,
    housekeeperList:[],
    aunt_info:{},
    replace:false,
  },
 
  onLoad(options) {
    if(options.order_id){
      this.setData({
        order_id:options.order_id,
      })
      this.gethousekeeperList()
    }else if(options.replace){
      this.setData({
        replace:true
      })
      this.getList()
    }
  },

  onReachBottom(){
    if(!this.data.replace){
      this.gethousekeeperList()
    }else{
      this.getList()
    }
  },

  getList(){//更换家政员列表
    if(!this.data.flag){
      return
    }
    this.setData({
      flag:false
    })
    let data = {
      type:1,
      page:this.data.page,
      limit:10
    }
    getApp().globalData.gets('/mer/store/aunt/lst',data).then(res=>{
      wx.stopPullDownRefresh();
      if (res.data.data.list.length == 0) {
        this.setData({
          flag: false
        })
      } else {
        let arr = this.data.housekeeperList.concat(res.data.data.list);
        this.setData({
          housekeeperList: arr,
          flag: true,
          page: this.data.page + 1
        })
      }
    })
  },

  gethousekeeperList(){
    if(!this.data.flag){
      return
    }
    this.setData({
      flag:false
    })
    app.globalData.post({
      data:{
        do: 'OrderAuntMeeting',
        pagesize:10,
        order_id:this.data.order_id,
        page:this.data.page,
      }
    }).then(res=>{
      wx.stopPullDownRefresh();
      if(res.data.result.length==0){
        this.setData({
          flag:false
        })
      }else{
        let arr = this.data.housekeeperList.concat(res.data.result);
        this.setData({
          flag:true,
          housekeeperList:arr,
          page:this.data.page+1
        })
      }
    })
  },

  changekeywords(e){//搜索家政员
    this.setData({
      name:e.detail.value,
      page:1,
      flag:true,
      housekeeperList:[],
    })
    this.gethousekeeperList()
  },

  change_aunt(e){
    if(!this.data.replace){
      this.setData({
        aunt_info:this.data.housekeeperList[e.detail.value].aunt_msg
      })
    }else{
      this.setData({
        aunt_info:this.data.housekeeperList[e.detail.value]
      })
    }
  },

  bottomTap(){
    wx.setStorageSync('get_aunt_info', this.data.aunt_info)
    wx.navigateBack({
      delta: 1,
    })
  },
 
})